﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using BusinessLayer;
using Ocean.OceanFramework.MVVM;
using BusinessEntityObjects;
using Ocean.OceanFramework.CommonDialog;
using Ocean.OceanFramework.WPF.Utility;
using System.Windows.Input; 

namespace WPFLOBMVVM.ViewModel
{
    public class ContactViewModel : EditFormViewModelBase
    {

        #region " Declarations "

        private ICommand _cmdBlogNavigateCommand;
        private ICommand _cmdFeedNavigateCommand;
        private Contact _objContact;

        #endregion

        #region " Properties "

        public Contact Contact
        {
            get { return _objContact; }
            set
            {
                _objContact = value;
                OnPropertyChanged("Contact");
            }
        }

        #endregion

        #region " Command Properties "

        public ICommand BlogNavigateCommand
        {
            get
            {

                if (_cmdBlogNavigateCommand == null)
                {
                    _cmdBlogNavigateCommand = new RelayCommand(BlogNavigateExecute, CanBlogNavigateExecute);
                }

                return _cmdBlogNavigateCommand;
            }
        }

        public ICommand FeedNavigateCommand
        {
            get
            {

                if (_cmdFeedNavigateCommand == null)
                {
                    _cmdFeedNavigateCommand = new RelayCommand(FeedNavigateExecute, CanFeedNavigateExecute);
                }

                return _cmdFeedNavigateCommand;
            }
        }

        #endregion

        #region " Constructor "

        public ContactViewModel(Contact obj)
        {
            base.ViewModelFriendlyName = "Contacts";
            _objContact = obj;
        }

        #endregion

        #region " Command Methods "

        private void BlogNavigateExecute(object param)
        {

            if (CanBlogNavigateExecute(param))
            {

                try
                {
                    Helpers.StartProcessWithFileName(this.Contact.BlogURL);
                }

                catch (Exception ex)
                {
                    ViewModelUIService.ExceptionDialog(ex, 0);
                }
            }


        }

        private bool CanBlogNavigateExecute(object param)
        {
            return _objContact != null && _objContact.BlogURL.Length > 0 && string.IsNullOrEmpty( _objContact["BlogURL"]);
        }

        private bool CanFeedNavigateExecute(object param)
        {
            return _objContact != null && _objContact.FeedURL.Length > 0 && string.IsNullOrEmpty(_objContact["FeedURL"]);
        }

        private void FeedNavigateExecute(object param)
        {

            if (CanFeedNavigateExecute(param))
            {

                try
                {
                    Helpers.StartProcessWithFileName(this.Contact.FeedURL);
                }

                catch (Exception ex)
                {
                    ViewModelUIService.ExceptionDialog(ex, 0);
                }
            }


        }
    }

        #endregion 
}
